﻿//
// Copyright (c) 2024 BPergaofeng
//

#include "BPerThread2.h"
#include <stdio.h>
#define bPer_error printf

BPerThread::BPerThread(){
#ifndef _MSC_VER

    m_thread=0;
#endif
}
BPerThread::~BPerThread(){
#ifdef _MSC_VER
   #if !BPer_Enable_Phtread
  //  if(m_thread) CloseHandle(m_thread);
    //m_thread=0;
    #endif
#endif
}

int32_t BPerThread::start()
{
    if (BPer_thread_create(&m_thread, 0, &BPerThread::go, this))
    {
        bPer_error("BPerThread::start could not start thread");
        return -1;
    }

    return 0;
}

void* BPerThread::go(void* obj)
{
    reinterpret_cast<BPerThread*>(obj)->run();
    return NULL;
}

void* BPerThread::join()
{
    void* ret;
    bPer_thread_join(m_thread, &ret);
    return ret;
}

BPer_thread_t BPerThread::getThread()
{
    return m_thread;
}
/**
int32_t BPerThread::detach()
{
    return bPer_thread_detach(m_thread);
}

int32_t BPerThread::equals(BPerThread* t)
{
    return bPer_thread_equal(m_thread, t->getThread());
}

void BPerThread::exitThread(void* value_ptr)
{
	bPer_thread_exit(value_ptr);
}

int32_t BPerThread::cancel()
{
    return pthread_cancel(m_thread);
}
**/
